<template>
	<view class="list-item u-f-ac">
		<!-- <image src="../../static/logo.png" mode="widthFix" lazy-load></image> -->
		<view class="content">
			<view class="question u-f-jsb">
				{{item.question}} <view class="button" @click="deleteQuestion(item._id)">删除</view>
			</view>
			<view class="answer">
				{{item.answer}}
			</view>
			<view class="time">{{item.created | formateTime}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			item:{
				type:Object,
				default(){
					return {}
				}
			}
		},
		filters:{
			formateTime(time){
				if(time==null){
					return;
				}
				let date=new Date(time);
				let y=date.getFullYear();
				let m=date.getMonth()+1;
				let d=date.getDate()
				let mm=date.getMinutes()
				let ss=date.getSeconds()
				return `${y}-${m}-${d} ${mm}:${ss}`
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			deleteQuestion(id){
				
				this.$api.delete_question({
						question_id:id,
				}).then((res)=>{
					uni.showToast({
						title:"删除成功",
						icon:'none'
					});
					this.$emit('afterDelete');
					
				}).catch((err)=>{
					uni.showToast({
						title:"删除失败",
						icon:'none'
					})
					console.log(err);
				})
			},
		}
	}
</script>

<style lang="scss">
.list-item{
		border-bottom: 4rpx solid #eeeeee;
		padding: 20rpx 14rpx;
		background-color: #FFFFFF;
		image{
			width: 100rpx;
			height: 100rpx;
			border-radius: 100%;
			margin-right: 20rpx;
		}
		.content{
			flex: 1;
			.question{
				font-size: 35rpx;
				font-weight: bold;		
				.button{
					padding: 4rpx 18rpx;
					background-color: #FF3333;
					color: #FFFFFF;
				}
			}
			.answer{
				font-size: 28rpx;
				padding: 20rpx 0;
			}
			.time{
				text-align: right;
				color: #999999;
				font-size: 24rpx;
				flex-shrink: 0;
			}
		}
	}
</style>
